package com.datastructure.test.twoqueueofstack;

import java.util.LinkedList;
import java.util.Queue;

public class TwoQueueOfStack1 {

    public static void main(String[] args) {
        TwoQueueOfStack1 twoQueueOfStack = new TwoQueueOfStack1();
        System.out.println(twoQueueOfStack.empty());
        twoQueueOfStack.push(1);
        System.out.println(twoQueueOfStack.top());
        System.out.println(twoQueueOfStack.empty());
    }

    Queue<Integer> queue1 = new LinkedList();
    Queue<Integer> queue2 = new LinkedList();

    public void push(int element) {
        queue2.offer(element);
        while(!queue1.isEmpty()){
            queue2.offer(queue1.poll());
        }
        Queue<Integer> tmp = queue1;
        queue1 = queue2;
        queue2 = tmp;
    }

    public int pop() {
        return queue1.poll();
    }

    public int top() {
        return queue1.peek();
    }

    public boolean empty() {
        return queue1.isEmpty();
    }
}
